var windowWidth = getApp().globalData.systemInfo.windowWidth;

Component({
    externalClasses: [ "custom-cell-class" ],
    options: {
        multipleSlots: !0
    },
    properties: {
        index: String,
        key: String,
        height: {
            type: String,
            value: "140rpx"
        },
        right: {
            type: Array,
            value: [],
            observer: "_getSlideWidth"
        }
    },
    relations: {
        "../cell-swipe-group/cell-swipe-group": {
            type: "parent"
        }
    },
    data: {
        windowWidth: windowWidth,
        slideWidth: 0,
        x: 0,
        out: !1,
        isLastCell: !0
    },
    methods: {
        _getSlideWidth: function(e) {
            var i = this;
            e && e.length && this.createSelectorQuery().select(".swiped-btn").boundingClientRect(function(t) {
                t ? (i.setData({
                    slideWidth: t.width
                }), i.boundary = t.width / 4) : i._getSlideWidth(e);
            }).exec();
        },
        _getParent: function() {
            return this.getRelationNodes("../cell-swipe-group/cell-swipe-group")[0] || {
                resetPosition: function() {}
            };
        },
        _resetPostion: function() {
            var t = this.data, e = t.index, i = t.key;
            this._getParent().resetPosition(e, i);
        },
        _onTouchStart: function(t) {
            this.startX = t && t.changedTouches[0].pageX;
        },
        _onTouchEnd: function(t) {
            this.endX = t.changedTouches[0].pageX;
            var e, i = this.startX, n = this.endX, s = this.boundary, o = this.data, a = o.slideWidth, d = o.index, h = o.key, r = i - n;
            r < s ? e = 0 : s < r ? (e = -a, this._resetPostion(d, h)) : (r < a || r < 0) && (e = 0), 
            this.moveAnimation(e);
        },
        moveAnimation: function(t) {
            isNaN(t) || this.setData({
                x: t
            });
        },
        _onChange: function(t) {
            var e = this.data.count, i = t.detail.x;
            !e && i < -this.boundary ? this.setData({
                out: !0
            }) : e && i >= -this.boundary && this.setData({
                out: !1
            });
        },
        _onView: function() {
            this._resetPostion(-1);
        },
        _onTap: function(t) {
            var e = t.currentTarget.dataset.method, i = this.data, n = i.index, s = i.key;
            this._getParent().emitEvent(e, n, s);
        },
        updateIsLastCell: function(t) {
            this.setData({
                isLastCell: t
            });
        }
    }
});